<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

<!--          <a-col :md="6" :sm="8">-->
<!--            <a-form-item label="栏目">-->
<!--              &lt;!&ndash; <j-dict-select-tag v-model="queryParam.channelId" :triggerChange="false" dictCode="cms_channel"/> &ndash;&gt;-->
<!--              <j-category-select :triggerChange="false" pid="cms_channel_tree" pcode="cms_channel_tree"  v-model="queryParam.channelId"/>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :md="6" :sm="8">
            <a-form-item label="标题">
              <j-input v-model="queryParam.title" placeholder="请输入标题"></j-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd2('政策')" type="primary" icon="plus">新增</a-button>-->
<!--      <a-button type="primary" icon="download" @click="handleExportXls('内容')">导出</a-button>-->
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
<!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
<!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
<!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
<!--      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

<!--        <template slot="originUrl" slot-scope="text, record">-->
<!--          <span data-clipboard-action="copy" class="copyLink" :data-clipboard-text="text" @click="copyLink">{{ text}}</span>-->
<!--        </template>-->
        <span slot="action" slot-scope="text, record">
          <a @click="copyLink(record)" class="copyLink">复制</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popover placement="left" trigger="hover">
                  <template slot="content">
                    <div class="item" :id="record.id" ref="qrCode" xss=removed></div>
                  </template>
                  <template slot="title">
                    <span>手机扫描二维码预览</span>
                    <a @click="handleQrCode(record)">显示</a>
                  </template>
                  <a >预览</a>
                </a-popover>
              </a-menu-item>
<!--              <a-menu-item>-->
<!--                <a @click="handleLog(record)">日志</a>-->
<!--              </a-menu-item>-->
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        <span slot="originUrl" slot-scope="text, record">
<!--          <a :href="record.originUrl" class="form-title" style="" target="_blank">-->
<!--            {{ text }}-->
<!--          </a>-->
          <a @click="openLink(record)" class="form-title">{{ text }}</a>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <!--    <cmsArticle-modal ref="modalForm" @ok="modalFormOk"></cmsArticle-modal>-->

    <cms-article-z-x-modal ref="modalForm" @ok="modalFormOk"></cms-article-z-x-modal>
    <!-- 数据日志列表 -->
    <data-log-bus-list ref="logList" tableName="cms_article"></data-log-bus-list>
  </a-card>
</template>

<script>
import CmsArticleZXModal from './modules/CmsArticleZXModal';
import { JeecgListMixin } from '@/mixins/JeecgListMixin';
import DataLogBusList from '@/views/system/DataLogBusList.vue'
import JInput from '@/components/jeecg/JInput.vue'
import pick from 'lodash.pick'
import Vue from 'vue'
import QRCode from 'qrcodejs2'  // 引入qrcode
import JCategorySelect from '@/components/jeecg/JCategorySelect'
export default {
  name: "CmsArticleZXList",
  mixins:[JeecgListMixin],
  components: {
    CmsArticleZXModal,
    DataLogBusList,
    JInput,
    JCategorySelect
  },
  data () {
    return {
      description: '内容管理页面',
      // 表头
      columns: [



        /*{
             title: '录入部门',
             align:"center",
             dataIndex: 'departId'
            },*/

        // {
        //   title: '栏目',
        //   align:"center",
        //   dataIndex: 'channelId',
        //   ellipsis: true,
        // },
        {
          title: '标题',
          align:"left",
          dataIndex: 'title',
          // width:660,
          scopedSlots: {
            customRender: 'originUrl'
          }
        },
        // {
        //   title: '短标题',
        //   align:"center",
        //   dataIndex: 'shortTitle',
        //   ellipsis: true,
        // },

        {
          title: '发布日期',
          align:"center",
          dataIndex: 'releaseDate',
          width: 150,
        },
        // {
        //   title: '外链链接',
        //   align:"center",
        //   dataIndex: 'originUrl',
        //   scopedSlots: {
        //     customRender: 'originUrl'
        //   }
        //   //scopedSlots: { customRender: 'originUrl' },
        // },


        // {
        //   title: '有效日期',
        //   align:"center",
        //   dataIndex: 'validDate'
        // },

        // {
        //   title: '操作',
        //   dataIndex: 'action',
        //   align:"center",
        //   scopedSlots: { customRender: 'action' },
        // }
      ],
      url: {
        list: "/cxm/cmsArticle/list1?channelId=政策",
        delete: "/cxm/cmsArticle/delete",
        deleteBatch: "/cxm/cmsArticle/deleteBatch",
        exportXlsUrl: "cxm/cmsArticle/exportXls",
        importExcelUrl: "cxm/cmsArticle/importExcel",
      },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  mounted () {
  },
  methods: {
    handleQrCode(record){
      this.$nextTick(() => {
        const codeHtml = document.getElementById(record.id);
        if(codeHtml!=null){
          codeHtml.innerHTML = "";
          let qr = new QRCode(codeHtml, {
            width: 150,
            height: 150, // 高度
            text: record.originUrl // 二维码内容
            // render: 'canvas' // 设置渲染方式（有两种方式 table和canvas，默认是canvas）
            // background: '#f0f',
            // foreground: '#ff0'
          })
        }
      });
    },
    handleEdit: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "编辑";
      this.$refs.modalForm.disableSubmit = false;
    },
    copyLink (data) {
      const that = this;
      let clipboard = new this.clipboard('.copyLink', {
        text: function () {
          return data.originUrl
        }
      });
      clipboard.on('success',() => {
        that.$message.success("复制成功")
        clipboard.destroy()
      });
      clipboard.on('error',() => {
        that.$message.success("复制失败")
        clipboard.destroy()
      });
    },
    openLink(data){
      const that = this;
      let link = data.originUrl
      console.log(link)
      window.open(link,'_blank')
    },
  }
}
</script>
<style lang="stylus" scoped>
.form-title {
  color: #595959 !important;

&:hover {
   text-decoration: underline;
 }
}
</style>